package slideWindows;

import javax.swing.*;
import java.util.*;

/**
 * @Author: Darven
 * @CreateTime: 2025-04-02  18:18
 * @Description: TODO
 */
public class P438 {

}

class P438Demo {
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> ans=new ArrayList<>();
        if(s.isEmpty()||p.isEmpty()){
            return ans;
        }
        int[] sCount=new int[26];
        int[] pCount=new int[26];
        for(char c:p.toCharArray()){
            pCount[c-'a']++;
        }
        int n=s.length();
        int left=0;
        int right=0;
        while (right<n){
            sCount[s.charAt(right)-'a']++;
            if((right-left+1)==p.length()){
                int flag=0;
                for(int i=0;i<26;i++){
                    if(pCount[i]!=sCount[i]){
                        flag=1;
                        break;
                    }
                }
                if(flag==0){
                    ans.add(left);

                }
                sCount[s.charAt(left)-'a']--;
                left++;
            }
            right++;
        }
        return ans;
    }
}
